
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="d" uri="/WEB-INF/resource.tld" %>

<sec:authentication property="principal" var="currentPrincipal" scope="page" />

<fmt:setBundle basename="ApplicationMessage" />
<fmt:setLocale value="zh_CN" />

<!DOCTYPE html>
<html lang="zh-CN">
<head>

  <%@ include file="/WEB-INF/include/meta.jsp"%>
  <%@ include file="/WEB-INF/include/css.jsp"%>
  
</head>

<body>

  <%@ include file="/WEB-INF/include/header.jsp"%>
  
  <%@ include file="/WEB-INF/include/menu.jsp"%>

  <div class="container main-content">

    <div class="panel panel-default x-panel x-panel-layout">

      <div class="panel-heading">
        <ol class="breadcrumb">
          <li><a href="${ctx.host}/system">电商管理</a></li>
          <li class="active">课程管理</li>
        </ol>
      </div>

      <div class="panel-body">

        <div class="col-xs-2 x-panel-layout-left no-horizontal-padding">
          <%@ include file="/WEB-INF/include/submenu.jsp"%>
        </div>

        <div class="col-xs-10 x-panel-layout-right">

          <div class="x-breadcrumb-wrapper">
            <div class="x-breadcrumb clearfix">
              <h2><i class="glyphicon glyphicon-fire" title=""></i>&nbsp;&nbsp;<span>课程管理&nbsp;-&nbsp;排期表</span></h2>
              <div class="pull-right">
                <c:choose>
                  <c:when test="${not empty currentPrincipal.site}">
                    <span class="current-branchCode">${currentPrincipal.site.name}</span>
                  </c:when>
                  <c:otherwise>
                    <select name="site">
                      <option value="">所有门店</option>
                      <c:forEach var="site" items="${persist.getSites(currentPrincipal.id)}">
                        <option value="${site.id}" ${site.id == param.site ? 'selected' : ''}>${site.name}</option>
                      </c:forEach>
                    </select>
                  </c:otherwise>
                </c:choose>
              </div>
            </div>
          </div>
          
          <div class="form-horizontal clearfix" >
          
            <div class="color-annotation pull-left" style="width:490px;">
              <span><label class="individual"></label>1v1</span>
              <span><label class="year"></label>周期</span>
              <span><label class="special"></label>特色</span>
              <span><label class="annual-leave"></label>特色75min</span>
              <span><label class="posture"></label>专项</span>
              <span><label class="give"></label>赠课</span>
              <span><label class="rest"></label>休息</span>
              <span><label class="experience"></label>体验课</span>
              <span><label class="duty"></label>值班</span>
              <span><label class="business"></label>公出</span>
              <span><label class="conference"></label>会议</span>
              <span><label class="training"></label>培训</span>
            </div>
            
            <div class="btn-group pull-right" role="group" aria-label="..." style="margin-left: 30px;">
              <a href="${ctx.host}/schedules?site=${site.id}" class="btn btn-default">教练</a>
              <a href="${ctx.host}/schedules?coachview=false&site=${site.id}" class="btn btn-success">日期</a>
            </div>
            
            <div class="btn-group pull-right">
              <a href="${ctx.host}/schedules/search${not empty queryString ? '?' : ''}${queryString}" data-target="#" data-toggle="modal" class="btn btn-default x-btn btn-shadow btn-shadow-default init-button hide">
                <i class="glyphicon glyphicon-search"></i>&nbsp;&nbsp;过滤查询
              </a>
              <c:if test="${currentPrincipal.areaManager or currentPrincipal.siteManager or currentPrincipal.areaServer or currentPrincipal.siteServer or currentPrincipal.admin or currentPrincipal.root}">
                <a href="${ctx.host}/schedules/export-view?view=day" data-target="#export-schedule" data-toggle="modal" class="btn btn-default x-btn btn-shadow btn-shadow-default init-button hide">导出课程表</a>
              </c:if>
            </div>
            
          </div>
           
<%--            <div>
            <c:choose>
              <c:when test="${refer == 'search'}">
                <jsp:include page="/WEB-INF/jsps/course/schedule/schedule-page.jsp">
                  <jsp:param name="url" value="schedules/search" />
                  <jsp:param name="queryString" value="${queryString}" />
                </jsp:include>
              </c:when>
              <c:otherwise>
                <jsp:include page="/WEB-INF/jsps/course/schedule/schedule-page.jsp">
                  <jsp:param name="url" value="schedules" />
                  <jsp:param name="queryString" value="${queryString}" />
                </jsp:include>
              </c:otherwise>
            </c:choose>
          </div> --%>
           
            <c:set var="start" value="${persist.startEndHour(site)['start']}"/>
            <c:set var="end" value="${persist.startEndHour(site)['end']}"/>
            <div style="width:100%; padding-right: 17px;">
            <table class="table table-bordered schedule-table text-center scheduler-table" style="margin-top: 30px; margin-bottom: 0; font-size: 12px; width: 100%;">
              <colgroup>
                <col style="width: 70px">
                <col style="width:100px">
                <c:forEach var="hh"  begin="${start}" end="${end}">
                  <col></col>
                </c:forEach>
              </colgroup>
              <!-- schedule header -->
              <%@ include file="/WEB-INF/jsps/course/schedule/pattern/table-header.jsp"%>
              <!-- end schedule header -->
              <tbody>
                <tr>
                    <td>日期</td>
                    <td>教练</td>
                    <c:forEach var="hh"  begin="${start}" end="${end}">
                      <td colspan="2">${hh<10 ? '0' : ''}${hh}:00</td>
                    </c:forEach>
                  </tr>
              </tbody>
            </table>
            </div>
            <div style="width: 100%; overflow: scroll;" class="table-scroll-wrap schedule-table-scroll-wrap">
            <table class="table table-bordered schedule-table text-center scheduler-table" style="margin-top: 0px; font-size: 12px; width: 100%; table-layout: fixed;">
              <colgroup>
                <col style="width: 70px">
                <col style="width:100px">
                <c:forEach var="hh"  begin="${start}" end="${end}">
                  <col></col>
                </c:forEach>
              </colgroup>
              <tbody>
                
                <c:set var="coachRelations" value="${persist.coachRelations}"/>
                <c:forEach var="date" items="${dates}" varStatus='status'>
                  <tr>
                    <td rowspan="${not empty param.coachId ? 1 : persist.coaches(currentPrincipal.id, site.id).size()}" style="text-align: center; vertical-align: middle; background-color: #E8E8E8;"><fmt:formatDate value="${date}" pattern="M月dd日"/></td>
                    <c:forEach var="principal" items="${persist.coaches(currentPrincipal.id, site.id)}" varStatus="status">
                      <c:choose>
                        <c:when test="${not empty param.coachId}">
                          <c:if test="${principal.key eq param.coachId}">
                            <td>${principal.value.name}</td>
                            <fmt:formatDate value="${date}" pattern="yyyyMMdd" var="occurDate"></fmt:formatDate>
                            <fmt:formatDate value="${date}" pattern="yyyy-MM-dd" var="day"/>
                            <c:forEach var="hour" begin="${start}" end="${end}">
                              <c:set var="beforeHourKey" value="${principal.key}${occurDate}${(hour-1)<10 ? '0' : ''}${hour-1}00" />
                              <c:set var="beforeHalfhourKey" value="${principal.key}${occurDate}${(hour-1)<10 ? '0' : ''}${hour-1}30" />
                              <c:set var="hourKey" value="${principal.key}${occurDate}${hour<10 ? '0' : ''}${hour}00" />
                              <c:set var="halfhourKey" value="${principal.key}${occurDate}${hour<10 ? '0' : ''}${hour}30"/>
                              <c:if test="${empty courseSchedules[beforeHalfhourKey] and (empty courseSchedules[beforeHourKey] || (not empty courseSchedules[beforeHourKey] && courseSchedules[beforeHourKey][0].course.courseUnit != 'NORMAL_EXPERIENCE' && courseSchedules[beforeHourKey][0].course.courseUnit != 'SPECIAL_UNION'))}">
                                <td data-hour="${hourKey}" 
                                    class="ellipsis ${persist.getScheduleAlias(courseSchedules[hourKey][0], restSchedules[hourKey])}"
                                    colspan="${not empty courseSchedules[hourKey] ? courseSchedules[hourKey][0].course.isLongColpan() ? 3 : 2 : ''}">
                                  <c:choose>
                                    <c:when test="${not empty courseSchedules[hourKey]}">
                                      <a class="${courseSchedules[hourKey][0].scheduleStatus.finish ? 'finished' : courseSchedules[hourKey][0].scheduleStatus.expiry ? 'expiry' : ''}" href="/individual-rounds/${courseSchedules[hourKey][0].courseRound.id}" style="color:#fff">
                                          ${courseSchedules[hourKey][0].student.name}
                                      </a>
                                    </c:when>
                                    <c:when test="${empty courseSchedules[hourKey] and empty restSchedules[hourKey]}">

                                    </c:when>
                                    <c:when test="${empty courseSchedules[hourKey] and not empty restSchedules[hourKey] and empty persist.containDuty(restSchedules[hourKey])}">
                                      值班
                                    </c:when>
                                    <c:when test="${empty courseSchedules[hourKey] and not empty restSchedules[hourKey] and not empty persist.containDuty(restSchedules[hourKey])}">
                                      ${persist.containDuty(restSchedules[hourKey]).coachRestType.description}
                                    </c:when>
                                  </c:choose>
                                </td>
                              </c:if>
                              <c:if test="${empty courseSchedules[hourKey] and (empty courseSchedules[beforeHalfhourKey] || (not empty courseSchedules[beforeHalfhourKey] && courseSchedules[beforeHalfhourKey][0].course.courseUnit != 'NORMAL_EXPERIENCE' && courseSchedules[beforeHalfhourKey][0].course.courseUnit != 'SPECIAL_UNION'))}">
                                <td data-hour="${halfhourKey}" 
                                    class="ellipsis  ${persist.getScheduleAlias(courseSchedules[halfhourKey][0], restSchedules[halfhourKey])}"
                                    colspan="${not empty courseSchedules[halfhourKey] ? courseSchedules[halfhourKey][0].course.isLongColpan() ? 3 : 2 : ''}">
                                  <c:choose>
                                    <c:when test="${not empty courseSchedules[halfhourKey]}">
                                      <a class="${courseSchedules[halfhourKey][0].scheduleStatus.finish ? 'finished' : courseSchedules[halfhourKey][0].scheduleStatus.expiry ? 'expiry' : ''}" href="/individual-rounds/${courseSchedules[halfhourKey][0].courseRound.id}" style="color:#fff">
                                          ${courseSchedules[halfhourKey][0].student.name}
                                      </a>
                                    </c:when>
                                    <c:when test="${empty courseSchedules[halfhourKey] and empty restSchedules[halfhourKey]}">

                                    </c:when>
                                    <c:when test="${empty courseSchedules[halfhourKey] and not empty restSchedules[halfhourKey] and empty persist.containDuty(restSchedules[halfhourKey])}">
                                      值班
                                    </c:when>
                                    <c:when test="${empty courseSchedules[halfhourKey] and not empty restSchedules[halfhourKey] and not empty persist.containDuty(restSchedules[halfhourKey])}">
                                      ${persist.containDuty(restSchedules[halfhourKey]).coachRestType.description}
                                    </c:when>
                                  </c:choose>
                                </td>
                              </c:if>
                            </c:forEach>
                          </c:if>
                        </c:when>
                        <c:otherwise>
                          <c:if test="${status.index eq 0}">
                            <td>${principal.value.name}</td>
                            <fmt:formatDate value="${date}" pattern="yyyyMMdd" var="occurDate"></fmt:formatDate>
                            <fmt:formatDate value="${date}" pattern="yyyy-MM-dd" var="day"/>
                            <c:forEach var="hour" begin="${start}" end="${end}">
                                <c:set var="beforeHourKey" value="${principal.key}${occurDate}${(hour-1)<10 ? '0' : ''}${hour-1}00" />
                                <c:set var="beforeHalfhourKey" value="${principal.key}${occurDate}${(hour-1)<10 ? '0' : ''}${hour-1}30" />
                                <c:set var="hourKey" value="${principal.key}${occurDate}${hour<10 ? '0' : ''}${hour}00" />
                                <c:set var="halfhourKey" value="${principal.key}${occurDate}${hour<10 ? '0' : ''}${hour}30"/>
                                <c:if test="${empty courseSchedules[beforeHalfhourKey] and (empty courseSchedules[beforeHourKey] || (not empty courseSchedules[beforeHourKey] && courseSchedules[beforeHourKey][0].course.courseUnit != 'NORMAL_EXPERIENCE' && courseSchedules[beforeHourKey][0].course.courseUnit != 'SPECIAL_UNION'))}">
                                  <td data-hour="${hourKey}" 
                                      class="ellipsis ${persist.getScheduleAlias(courseSchedules[hourKey][0], restSchedules[hourKey])}"
                                      colspan="${not empty courseSchedules[hourKey] ? courseSchedules[hourKey][0].course.isLongColpan() ? 3 : 2 : ''}">
                                    <c:choose>
                                      <c:when test="${not empty courseSchedules[hourKey]}">
                                        <a class="${courseSchedules[hourKey][0].scheduleStatus.finish ? 'finished' : courseSchedules[hourKey][0].scheduleStatus.expiry ? 'expiry' : ''}" href="/individual-rounds/${courseSchedules[hourKey][0].courseRound.id}" style="color:#fff">
                                            ${courseSchedules[hourKey][0].student.name}
                                        </a>
                                      </c:when>
                                      <c:when test="${empty courseSchedules[hourKey] and empty restSchedules[hourKey]}">

                                      </c:when>
                                      <c:when test="${empty courseSchedules[hourKey] and not empty restSchedules[hourKey] and empty persist.containDuty(restSchedules[hourKey])}">
                                        值班
                                      </c:when>
                                      <c:when test="${empty courseSchedules[hourKey] and not empty restSchedules[hourKey] and not empty persist.containDuty(restSchedules[hourKey])}">
                                        ${persist.containDuty(restSchedules[hourKey]).coachRestType.description}
                                      </c:when>
                                    </c:choose>
                                  </td>
                                </c:if>
                               
                                <c:if test="${empty courseSchedules[hourKey] and (empty courseSchedules[beforeHalfhourKey] || (not empty courseSchedules[beforeHalfhourKey] && courseSchedules[beforeHalfhourKey][0].course.courseUnit != 'NORMAL_EXPERIENCE' && courseSchedules[beforeHalfhourKey][0].course.courseUnit != 'SPECIAL_UNION'))}">
                                  <td data-hour="${halfhourKey}" 
                                      class="ellipsis ${persist.getScheduleAlias(courseSchedules[halfhourKey][0], restSchedules[halfhourKey])}"
                                      colspan="${not empty courseSchedules[halfhourKey] ? courseSchedules[halfhourKey][0].course.isLongColpan() ? 3 : 2 : ''}">
                                    <c:choose>
                                      <c:when test="${not empty courseSchedules[halfhourKey]}">
                                        <a class="${courseSchedules[halfhourKey][0].scheduleStatus.finish ? 'finished' : ''}" href="/individual-rounds/${courseSchedules[halfhourKey][0].courseRound.id}" style="color:#fff">
                                            ${courseSchedules[halfhourKey][0].student.name}
                                        </a>
                                      </c:when>
                                      <c:when test="${empty courseSchedules[halfhourKey] and empty restSchedules[halfhourKey]}">

                                      </c:when>
                                      <c:when test="${empty courseSchedules[halfhourKey] and not empty restSchedules[halfhourKey] and empty persist.containDuty(restSchedules[halfhourKey])}">
                                        值班
                                      </c:when>
                                      <c:when test="${empty courseSchedules[halfhourKey] and not empty restSchedules[halfhourKey] and not empty persist.containDuty(restSchedules[halfhourKey])}">
                                        ${persist.containDuty(restSchedules[halfhourKey]).coachRestType.description}
                                      </c:when>
                                    </c:choose>
                                  </td>
                                </c:if>
                            </c:forEach>
                          </c:if>
                        </c:otherwise>
                      </c:choose>
                    </c:forEach>
                  </tr>
                  <c:if test="${empty param.coachId}">
                    <c:forEach var="principal" items="${persist.coaches(currentPrincipal.id, site.id)}" begin="1">
                      <tr>
                        <td>${principal.value.name}</td>
                        <fmt:formatDate value="${date}" pattern="yyyyMMdd" var="occurDate"></fmt:formatDate>
                        <fmt:formatDate value="${date}" pattern="yyyy-MM-dd" var="day" />
                        <c:forEach var="hour" begin="${start}" end="${end}">
                          <c:set var="beforeHourKey" value="${principal.key}${occurDate}${(hour-1)<10 ? '0' : ''}${hour-1}00" />
                          <c:set var="beforeHalfhourKey" value="${principal.key}${occurDate}${(hour-1)<10 ? '0' : ''}${hour-1}30" />
                          <c:set var="hourKey" value="${principal.key}${occurDate}${hour<10 ? '0' : ''}${hour}00" />
                          <c:set var="halfhourKey" value="${principal.key}${occurDate}${hour<10 ? '0' : ''}${hour}30"/>
                          <c:if test="${empty courseSchedules[beforeHalfhourKey] and (empty courseSchedules[beforeHourKey] || (not empty courseSchedules[beforeHourKey] && courseSchedules[beforeHourKey][0].course.courseUnit != 'NORMAL_EXPERIENCE' && courseSchedules[beforeHourKey][0].course.courseUnit != 'SPECIAL_UNION'))}">
                            <td data-hour="${hourKey}" 
                                class="ellipsis ${persist.getScheduleAlias(courseSchedules[hourKey][0], restSchedules[hourKey])}"
                                colspan="${not empty courseSchedules[hourKey] ? courseSchedules[hourKey][0].course.isLongColpan() ? 3 : 2 : ''}">
                              <c:choose>
                                <c:when test="${not empty courseSchedules[hourKey]}">
                                  <a class="${courseSchedules[hourKey][0].scheduleStatus.finish ? 'finished' : courseSchedules[hourKey][0].scheduleStatus.expiry ? 'expiry' : ''}" href="/individual-rounds/${courseSchedules[hourKey][0].courseRound.id}" style="color:#fff">
                                      ${courseSchedules[hourKey][0].student.name}
                                  </a>
                                </c:when>
                                <c:when test="${empty courseSchedules[hourKey] and empty restSchedules[hourKey]}">

                                </c:when>
                                <c:when test="${empty courseSchedules[hourKey] and not empty restSchedules[hourKey] and empty persist.containDuty(restSchedules[hourKey])}">
                                  值班
                                </c:when>
                                <c:when test="${empty courseSchedules[hourKey] and not empty restSchedules[hourKey] and not empty persist.containDuty(restSchedules[hourKey])}">
                                  ${persist.containDuty(restSchedules[hourKey]).coachRestType.description}
                                </c:when>
                              </c:choose>
                            </td>
                          </c:if>
                          <c:if test="${empty courseSchedules[hourKey] and (empty courseSchedules[beforeHalfhourKey] || (not empty courseSchedules[beforeHalfhourKey] && courseSchedules[beforeHalfhourKey][0].course.courseUnit != 'NORMAL_EXPERIENCE' && courseSchedules[beforeHalfhourKey][0].course.courseUnit != 'SPECIAL_UNION'))}">
                            <td data-hour="${halfhourKey}" 
                                class="ellipsis ${persist.getScheduleAlias(courseSchedules[halfhourKey][0], restSchedules[halfhourKey])}"
                                colspan="${not empty courseSchedules[halfhourKey] ? courseSchedules[halfhourKey][0].course.isLongColpan() ? 3 : 2 : ''}">
                              <c:choose>
                                <c:when test="${not empty courseSchedules[halfhourKey]}">
                                  <a class="${courseSchedules[halfhourKey][0].scheduleStatus.finish ? 'finished' : courseSchedules[halfhourKey][0].scheduleStatus.expiry ? 'expiry' : ''}" href="/individual-rounds/${courseSchedules[halfhourKey][0].courseRound.id}" style="color:#fff">
                                      ${courseSchedules[halfhourKey][0].student.name}
                                  </a>
                                </c:when>
                                <c:when test="${empty courseSchedules[halfhourKey] and empty restSchedules[halfhourKey]}">

                                </c:when>
                                <c:when test="${empty courseSchedules[halfhourKey] and not empty restSchedules[halfhourKey] and empty persist.containDuty(restSchedules[halfhourKey])}">
                                  值班
                                </c:when>
                                <c:when test="${empty courseSchedules[halfhourKey] and not empty restSchedules[halfhourKey] and not empty persist.containDuty(restSchedules[halfhourKey])}">
                                  ${persist.containDuty(restSchedules[halfhourKey]).coachRestType.description}
                                </c:when>
                              </c:choose>
                            </td>
                          </c:if>
                        </c:forEach>
                      </tr>
                    </c:forEach>
                    
                  </c:if>
                </c:forEach>
              </tbody>
            </table>
            </div>
              
        </div>

      </div>

    </div>

  </div>

  <%@ include file="/WEB-INF/include/footer.jsp"%>
  <%@ include file="/WEB-INF/include/script.jsp"%>
  <d:resource root="${ctx.resource}/build" type="script" src="js/page/course/schedule-index.js">
    <script type="text/javascript">
      var coachview = "${param.coachview}";
      var beginDate = "${param.beginDate}";
      var weekOffset = "${param.weekOffset}";
      var coachId = "${param.coachId}";
      require(['page/course/schedule-index'], function(page) {
        page.init({
          "coachview" : coachview,
          "beginDate" : beginDate,
          "weekOffset": weekOffset,
          "coachId" : coachId
        })
      })
    </script>
  </d:resource>

</body>

</html>

